-
Notifications
You must be signed in to change notification settings - Fork 5
Handle shell built-in commands #47
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
Signed-off-by: Itai-Nelken <[email protected]>
Signed-off-by: Itai-Nelken <[email protected]>
int easter_egg() { | ||
printf("You found the DollarSkip easter egg!\n"); | ||
return 0; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nevermind, I skipped past this part, i think this is pretty pointless, fun but pointless and dollarskip is made to merely pass the commands through, not be an actual application.
It should be a possibility that we remove this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm fine with removing it. I added it just as an example of how to override shell commands that are important enough to implement ourselves.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could also rename it to dollarskip
and make it print about and version info. If that's what we do, I'll remove the overriding shell commands as we can check for arguments in main(). That will also improve speed as we remove one loop.
A faster way to do this would be with a hash table (map
in go), but I didn't want to add my implementation (that is pretty big and not so readable).
Co-authored-by: CleanMachine1 <[email protected]>
Something I forgot to mention: this slows down dollarskip by about 0.030 seconds. |
Thats an extremely long time. I'm sure the average person will notice 😄 There is no issue. |
I made a version of the changes here (excluding the "wrapping" of commands) for DollarSkip-go.
|
This handles built-in shell commands.
this is done by using 2 arrays:
unhandled_shell_builtins
: A string array containing the names of built-in commands that don't work through DollarSkip (cd
for example).handled_shell_builtins
: An array forWrapper
(struct wrapper
) that holds commands we wrapped so they work through DollarSkip.To show how the handled shell built-ins work I added an "easter egg" command (
e_egg
). I thought about doingpwd
, but I don't want to rewrite the bash version.Closes #46
Signed-off-by: Itai-Nelken [email protected]